> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/jaypopat/cf_ai_duet/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-Hosting

> Run the Duet Go server directly on your machine

This guide covers running Duet by building and running the Go server directly.

## Prerequisites

* Go 1.25.4 or later
* SSH key pair for host authentication
* Access to a Cloudflare Worker (see [Cloudflare Worker setup](/deployment/cloudflare-worker))

## Build from Source

<Steps>
  <Step title="Clone the repository">
    Clone the Duet repository to your local machine:

    ```bash theme={null}
    git clone https://github.com/jaypopat/cf_ai_duet.git
    cd cf_ai_duet
    ```
  </Step>

  <Step title="Build the binary">
    Use the Makefile to build the Go binary:

    <CodeGroup>
      ```bash Make theme={null}
      make build
      ```

      ```bash Manual theme={null}
      go build -o bin/duet .
      ```
    </CodeGroup>

    This creates the `duet` binary in the `bin/` directory.
  </Step>

  <Step title="Generate SSH host key">
    Generate an SSH host key for the server:

    ```bash theme={null}
    mkdir -p .ssh
    ssh-keygen -t ed25519 -f .ssh/id_ed25519 -N ""
    ```
  </Step>

  <Step title="Run the server">
    Start the Duet server with your configuration:

    ```bash theme={null}
    ./bin/duet -addr :2222 -hostkey .ssh/id_ed25519 -worker https://your-worker.workers.dev
    ```
  </Step>
</Steps>

## Configuration

The Duet server accepts the following command-line flags:

| Flag       | Default           | Description                                                                     |
| ---------- | ----------------- | ------------------------------------------------------------------------------- |
| `-addr`    | `:2222`           | SSH server address and port                                                     |
| `-hostkey` | `.ssh/id_ed25519` | Path to SSH host key                                                            |
| `-worker`  | `""`              | Duet CF Worker base URL (e.g. `https://duet-cf-worker.<subdomain>.workers.dev`) |

<Note>
  The `-worker` flag is required for AI agent and sandbox features. Without it, only basic SSH pair programming will be available.
</Note>

## Development Mode

For local development with a local Cloudflare Worker:

<Steps>
  <Step title="Start both services">
    Run the development command to start both the Worker and Go server:

    ```bash theme={null}
    make dev
    ```

    This runs:

    * Cloudflare Worker on `http://localhost:8788`
    * Duet Go server on port `2222`
  </Step>

  <Step title="Connect to the server">
    Connect using SSH:

    ```bash theme={null}
    ssh <username>@localhost -p 2222
    ```
  </Step>
</Steps>

<Note>
  Development mode starts the Worker locally but AI inference still happens on Cloudflare's edge. Sandbox features require a paid Cloudflare plan.
</Note>

## Alternative: Use Remote Worker

To run the Go server locally while using a deployed Worker:

```bash theme={null}
make dev-remote
```

Or manually:

```bash theme={null}
go run main.go -worker https://duet-cf-worker.incident-agent.workers.dev
```

## Install Globally

To install Duet globally on your system:

```bash theme={null}
make install
```

This installs the binary using `go install`, making it available in your `$GOPATH/bin`.

## Production Considerations

<Warning>
  For production deployments, consider:

  * Using a reverse proxy (nginx, Caddy) for TLS termination
  * Running the server as a systemd service
  * Setting up proper firewall rules
  * Using a dedicated non-root user
  * Implementing rate limiting and connection limits
</Warning>

## Connecting to Your Server

Once running, users can connect via:

```bash theme={null}
ssh <username>@your-server.com -p 2222
```

Replace `your-server.com` with your actual domain or IP address, and `2222` with your configured port.
